home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Warrior’s Progress / source code / Source / Libraries / Memory / MasterPointer.h < prev    next >
Encoding:
Text File  |  1997-06-28  |  2.7 KB  |  76 lines  |  [TEXT/CWIE]

  1. // MasterPointer.h
  2.  
  3. #ifndef MasterPointer_h
  4. #define MasterPointer_h
  5.  
  6. #ifndef Integers_h
  7. #include "Integers.h"
  8. #endif
  9. #ifndef Assert_h
  10. #include "Assert.h"
  11. #endif
  12.  
  13. class MasterPointer
  14.   {
  15.     private:
  16.         void *pointer;
  17.         
  18.         // These don't exist
  19.             MasterPointer( const MasterPointer& );
  20.             void operator=( const MasterPointer& );
  21.  
  22.         MasterPointer()        {}
  23.         
  24.         static void ThrowAllocationError( OSErr, void * );
  25.         
  26.     public:
  27.         enum SystemHeap { systemHeap };
  28.         enum Temporary { temporary };
  29.         
  30.         static MasterPointer *MakeEmpty()                                        { return new MasterPointer; }
  31.         static MasterPointer *Make( uint32 size )                                { return new( size ) MasterPointer; }
  32.         static MasterPointer *MakeEmptyInSystemHeap()                        { return new( systemHeap ) MasterPointer; }
  33.         static MasterPointer *MakeInSystemHeap( uint32 size )                { return new( size, systemHeap ) MasterPointer; }
  34.         static MasterPointer *MakeTemporary( uint32 size )                    { return new( size, temporary ) MasterPointer; }
  35.         
  36.         void *operator new( uint32 pointerSize );
  37.         void *operator new( uint32 pointerSize, uint32 blockSize );
  38.         void *operator new( uint32 pointerSize, SystemHeap );
  39.         void *operator new( uint32 pointerSize, uint32 blockSize, SystemHeap );
  40.         void *operator new( uint32 pointerSize, uint32 blockSize, Temporary );
  41.         void operator delete( void * );
  42.         
  43.         void *Pointer() const        { return pointer; }
  44.         ::Ptr Ptr() const                { return static_cast<::Ptr>( pointer ); }
  45.         ::Handle Handle() const        { return reinterpret_cast<::Handle>( const_cast<void **>(&pointer) ); }
  46.         
  47.         bool IsEmpty() const                        { return pointer == 0; }
  48.         void BeEmpty()                                { EmptyHandle( Handle() ); }
  49.         void Allocate( uint32 size )            { Assert( IsEmpty() ); ReallocateHandle( Handle(), size ); }
  50.         
  51.         uint32 Size() const                        { Assert( !IsEmpty() ); return GetHandleSize( Handle() ); }
  52.         void SetSize( uint32 newSize )        { Assert( !IsEmpty() ); SetHandleSize( Handle(), newSize ); }
  53.         
  54.         SignedByte State() const                { return HGetState( Handle() ); }
  55.         void SetState( SignedByte state )    { HSetState( Handle(), state ); }
  56.         
  57.         void Lock()                                    { HLock( Handle() ); }
  58.         void Unlock()                                { HUnlock( Handle() ); }
  59.         
  60.         void AllowPurging()                        { HPurge( Handle() ); }
  61.         void ForbidPurging()                        { HNoPurge( Handle() ); }
  62.         
  63.         void BeResource()                            { HSetRBit( Handle() ); }
  64.         void BeNotResource()                        { HClrRBit( Handle() ); }
  65.         
  66.         static MasterPointer& At( ::Handle h )                    { return *reinterpret_cast<MasterPointer *>( h ); }
  67.         static MasterPointer& MasterPointerFor( void *p )    { return At( RecoverHandle( static_cast<::Ptr>(p) ) ); }
  68.         
  69.         void MoveHigh()                            { MoveHHi( Handle() ); }
  70.         void LockHigh()                            { HLockHi( Handle() ); }
  71.         
  72.         THz Zone() const                            { return HandleZone( Handle() ); }
  73.   };
  74.  
  75. #endif
  76.